package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("setmeal")
@RestController
public class SetmealController {

    @Autowired
    SetmealService setmealService;

/*    @RequestMapping("/add")
    public Result add(@RequestBody Setmeal setmeal,@RequestParam List<Integer> checkGroupIds){
        setmealService.add(setmeal,checkGroupIds);
        return new Result(true, MessageConstant.ADD_SETMEAL_SUCCESS);
    }*/


    @PostMapping("/add")
    public Result add(@RequestBody Setmeal setmeal,@RequestParam Integer[] checkGroupIds){
        setmealService.add(setmeal,checkGroupIds);
        return new Result(true, MessageConstant.ADD_SETMEAL_SUCCESS);
    }
    @RequestMapping("/edit/checkGroupIds")
    public Result edit(@RequestBody Setmeal setmeal,@RequestParam Integer[] checkGroupIds){
        setmealService.edit(setmeal,checkGroupIds);
        return new Result(true, MessageConstant.EDIT_SETMEAL_SUCCESS);
    }

    @RequestMapping("/findById/id")
    public Result getById(Integer id){
       Setmeal setmeals=setmealService.findById(id);
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmeals);
    }
    @RequestMapping("/findPage")
    public PageResult page(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult= setmealService.findPage(queryPageBean);

        return new PageResult(pageResult.getTotal(),pageResult.getRows());
    }
}
